﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OrderManager.aspx.cs" Inherits="Admin_OrderManager" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>订单处理</title>
    <link href="AdminCSS/style.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/gz-1.7.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        //显示订单明细
        function Display(id) {
            var tr = document.getElementById(id);
            if (tr.style.display == "none") {
                tr.style.display = "";
            }
            else {
                tr.style.display = "none";
            }
        }

        //加载订单信息
        function LoadOrderInfo(orderid, customername, orderamount) {
            $("#lblOrderId").html(orderid);
            $("#lblCustomerName").html(customername);
            $("#lblOrderAmount").html(orderamount);
            $("#CompleteOrder").show();
        }

        //订单完成处理
        function CompleteOrder() {
            var OrderId = document.getElementById("lblOrderId").innerHTML;
            var actualamount = document.getElementById("txtActualAmount").value;
            var txtDeliveryRemark = document.getElementById("txtDeliveryRemark").value;
            if (actualamount.length == 0) {
                alert("请填写实收金额！");
                $("#CompleteOrder").hide();
            }
            else {
                $.ajax({
                    async: false,
                    url: "../ajax/ajaxorder.ashx?methodName=CompleteOrder&Date=" + new Date() + "&orderid=" + OrderId + "&actualamount=" + actualamount + "&txtDeliveryRemark=" + encodeURI(txtDeliveryRemark),
                    type: "GET",
                    success: function (data, status) {
                        alert(data);
                        if (data == "ok") {
                            window.location.reload();
                        }
                        else {
                            alert("操作失败，请联系技术");
                        }
                    }
                });
            }
        }

        
         
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server" Interval="180000" OnTick="Timer1_Tick">
        </asp:Timer>
        订单号：<asp:TextBox ID="txtOrderId" runat="server" Width="90px"></asp:TextBox>
        E-Mail：<asp:TextBox ID="txtEmail" runat="server" Width="90px"></asp:TextBox>
        用户名：<asp:TextBox ID="txtCustomerName" runat="server" Width="70px"></asp:TextBox>
        电话号码：<asp:TextBox ID="txtTelNum" runat="server" Width="80px"></asp:TextBox>
        <asp:DropDownList ID="drpDate" runat="server">
            <asp:ListItem Value="CreateDate">下单日期</asp:ListItem>
            <asp:ListItem Value="DeliveryDate" Selected="True">配送日期</asp:ListItem>
        </asp:DropDownList>
        ：<asp:TextBox ID="txtBeginDate" runat="server" onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd'})"
            Width="70px"></asp:TextBox>
        -<asp:TextBox ID="txtEndDate" runat="server" onfocus="WdatePicker()" Width="70px"></asp:TextBox>
        订单类型：<asp:DropDownList ID="drpOrderType" runat="server">
            <asp:ListItem Value="0">全部</asp:ListItem>
            <asp:ListItem Value="1">网络单</asp:ListItem>
            <asp:ListItem Value="2">电话单</asp:ListItem>
        </asp:DropDownList>
        付款方式<asp:DropDownList ID="drpPaymentType" runat="server">
            <asp:ListItem>请选择</asp:ListItem>
            <asp:ListItem Value="1">货到付款</asp:ListItem>
            <asp:ListItem Value="2">财付通</asp:ListItem>
            <asp:ListItem Value="3">支付宝</asp:ListItem>
        </asp:DropDownList>
        状态：<asp:DropDownList ID="drpOrderState" runat="server">
            <asp:ListItem Value="0">全部</asp:ListItem>
            <asp:ListItem Value="1">未审核</asp:ListItem>
            <asp:ListItem Value="2">已审核</asp:ListItem>
            <asp:ListItem Value="3">正在派送</asp:ListItem>
            <asp:ListItem Value="4">已完成</asp:ListItem>
            <asp:ListItem Value="5">已取消</asp:ListItem>
            <asp:ListItem Value="6">已拒收</asp:ListItem>
        </asp:DropDownList>
        &nbsp;<asp:Button ID="btnQuery" runat="server" Text="查询" Width="70px" OnClick="btnQuery_Click" />
        &nbsp;<asp:Button ID="btnExportCSV" runat="server" OnClick="btnExportCSV_Click" Text="导出CSV"
            Width="70px" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table border="0" cellpadding="0" cellspacing="1" width="100%" style="background: Black;">
                    <tr style="height: 27px">
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>订单号</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>姓名</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>总价</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>实收</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>电话</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>下单时间</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>配送日期</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>配送时段</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>配送地址</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>状态</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>订单类型</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>付款方式</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>付款状态</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>订单备注</strong>
                        </td>
                        <td style="background: #DFDEDC; width: 4%" align="center">
                            <strong>操作</strong>
                        </td>
                    </tr>
                    <asp:Repeater ID="rptOrderList" runat="server" OnItemCommand="rptOrderList_ItemCommand"
                        OnItemDataBound="rptOrderList_ItemDataBound">
                        <ItemTemplate>
                            <tr id="row" runat="server" style="background: White; height: 27px;">
                                <td>
                                    <%#Eval("OrderId") %>
                                    <asp:HiddenField runat="server" ID="HOrderState" Value='<%#Eval("OrderState")%>' />
                                    <asp:HiddenField runat="server" ID="HOrderId" Value='<%#Eval("OrderId")%>' />
                                </td>
                                <td>
                                    <%#Eval("CustomerName")%>
                                </td>
                                <td>
                                    <%#Eval("OrderAmount") %>
                                </td>
                                <td>
                                    <%#Eval("ActualAmount")%>
                                </td>
                                <td>
                                    <%#Eval("TelNum")%>
                                </td>
                                <td>
                                    <%#Eval("CreateDate")%>
                                </td>
                                <td>
                                    <%#Convert.ToDateTime(Eval("DeliveryDate")).ToShortDateString()%>
                                </td>
                                <td>
                                    <%#Eval("DeliveryPeriodName")%>
                                </td>
                                <td>
                                    <%#Eval("RegionId")%><%#Eval("BusinessDistrictId")%><%#Eval("OfficeId")%><%#Eval("FloorId")%>
                                    <%#Eval("Address")%>
                                </td>
                                <td>
                                    <%# GetOrderState(Convert.ToInt16(Eval("OrderState")))%>
                                </td>
                                <td>
                                    <%#Eval("OrderType").ToString()=="1"?"网络单":"电话单"%>
                                </td>
                                <td>
                                    <%#GetPaymentType(Convert.ToInt16(Eval("PaymentType")))%>
                                </td>
                                <td>
                                    <%# GetPaymentState(Eval("PaymentType").ToString(), Eval("IsPay").ToString())%>
                                </td>
                                <td>
                                    <%#Eval("Memo").ToString() %>
                                </td>
                                <td>
                                    <a onclick="javascript:Display('tr<%#Eval("Id") %>')">详情</a>
                                    <asp:Button CommandArgument='<%#Eval("OrderId")%>' Visible="false" CommandName="Verify"
                                        runat="server" ID="btnVerify" Text="审核" />
                                    <asp:Button CommandArgument='<%#Eval("OrderId")%>' Visible="false" CommandName="Print"
                                        runat="server" ID="btnPrint" Text="打印" />
                                    <asp:Button CommandArgument='<%#Eval("OrderId")%>' Visible="false" CommandName="RePrint"
                                        runat="server" ID="btnRePrint" Text="重打" />
                                    <asp:Button CommandArgument='<%#Eval("OrderId")%>' Visible="false" CommandName="Cancel"
                                        runat="server" ID="btnCancel" Text="取消" />
                                    <asp:Button CommandArgument='<%#Eval("OrderId")%>' Visible="false" CommandName="Rejection"
                                        runat="server" ID="btnRejection" Text="拒收" />
                                    <%#Eval("OrderState").ToString()=="3"?"<input type=\"button\" id=\"btnComplete\" value=\"完成\" onclick=\"LoadOrderInfo('"+Eval("OrderId")+"','"+Eval("CustomerName")+"','"+Eval("OrderAmount")+"')\"' />":"" %>
                                </td>
                            </tr>
                            <tr style="height: 27px; display: none" id='tr<%#Eval("Id") %>'>
                                <td align="left" colspan="14" style="background: white">
                                    <br />
                                    <table border="0" cellpadding="0" cellspacing="1" width="90%" style="background: black;">
                                        <tr style="height: 27px">
                                            <td style="background: #DFDEDC; width: 4%" align="center">
                                                商品ID
                                            </td>
                                            <td style="background: #DFDEDC; width: 8%" align="center">
                                                商品名称
                                            </td>
                                            <td style="background: #DFDEDC; width: 8%" align="center">
                                                数量
                                            </td>
                                            <td style="background: #DFDEDC; width: 8%" align="center">
                                                单价
                                            </td>
                                            <td style="background: #DFDEDC; width: 12%" align="center">
                                                小计
                                            </td>
                                        </tr>
                                        <asp:Repeater runat="server" ID="rptOrderDetail">
                                            <ItemTemplate>
                                                <tr height="27px" id="rowdetail" style="background-color: White" runat="server">
                                                    <td style="width: 4%" align="center">
                                                        <%#Eval("Id")%>
                                                    </td>
                                                    <td style="width: 8%" align="center">
                                                        <%#Eval("ProductName")%>
                                                    </td>
                                                    <td style="width: 8%" align="center">
                                                        <%#Eval("Cnt")%>
                                                    </td>
                                                    <td style="width: 8%" align="center">
                                                        <%#Eval("Price")%>
                                                    </td>
                                                    <td style="width: 18%" align="center">
                                                        <%#Eval("Amount")%>
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </table>
                                    <br />
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
            PageSize="20">
        </webdiyer:AspNetPager>
        <div id="CompleteOrder" style="display: none; top: 40%; left: 40%; position: absolute;
            background-color: Black; width: 15%">
            <table width="100%" border="0" cellpadding="0" cellspacing="1" style="background: #ced7f7">
                <tr>
                    <td style="width: 30%">
                        订单号：
                    </td>
                    <td style="width: 70%">
                        <asp:Label ID="lblOrderId" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        客户姓名：
                    </td>
                    <td>
                        <asp:Label ID="lblCustomerName" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        订单金额：
                    </td>
                    <td>
                        <asp:Label ID="lblOrderAmount" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        实收金额：
                    </td>
                    <td>
                        <asp:TextBox ID="txtActualAmount" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        备注：
                    </td>
                    <td>
                        <asp:TextBox ID="txtDeliveryRemark" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="button" value="收单" onclick="javascript:CompleteOrder();" />
                    </td>
                </tr>
            </table>
            <input id="DivOrderId" runat="server" type="hidden" />
        </div>
    </div>
    </form>
</body>
</html>
